package com.studentsystem.service.impl;

import com.studentsystem.dao.GradeDao;
import com.studentsystem.dataobject.GradeDO;
import com.studentsystem.service.GradeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * (Grade)表服务实现类
 */
@Service("gradeService")
public class GradeServiceImpl implements GradeService {
    @Resource
    private GradeDao gradeDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public GradeDO queryById(Long id) {
        return this.gradeDao.queryById(id);
    }

    @Override
    public List<GradeDO> queryByStudentNumber(String studentNumber) {
        GradeDO gradeDO = new GradeDO();
        gradeDO.setStudentNumber(studentNumber);
        return this.gradeDao.queryAll(gradeDO);
    }

    @Override
    public List<GradeDO> queryGradeInfo(String studentNumber, Integer year, Integer term) {
        GradeDO gradeDO = new GradeDO();
        gradeDO.setStudentNumber(studentNumber);
        gradeDO.setYear(year);
        gradeDO.setTerm(term);
        return this.gradeDao.queryAll(gradeDO);
    }

    @Override
    public List<GradeDO> queryAll(String classs, Integer term, String courseName) {
        GradeDO gradeDO = new GradeDO();
        gradeDO.setClasss(classs);
        gradeDO.setCourseName(courseName);
        gradeDO.setTerm(term);
        return this.gradeDao.queryAll(gradeDO);
    }

    @Override
    public Map<String, GradeDO> queryAddedStudents(String classs, String courseName) {
        return this.gradeDao.queryAddedStudents(classs, courseName);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<GradeDO> queryAllByLimit(int offset, int limit) {
        return this.gradeDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param gradeDO 实例对象
     * @return 实例对象
     */
    @Override
    public Boolean insert(GradeDO gradeDO) {
        return this.gradeDao.insert(gradeDO) > 0;
    }

    /**
     * 修改数据
     *
     * @param gradeDO 实例对象
     * @return 实例对象
     */
    @Override
    public Boolean update(GradeDO gradeDO) {
        return this.gradeDao.update(gradeDO) > 0;
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.gradeDao.deleteById(id) > 0;
    }
}